//141
function hasCycle(head) {
  const sets = new Set();
  let temp = head;
  while (temp != null) {
    if (sets.has(temp)) {
      return true;
    }
    sets.add(temp);
    temp = temp.next;
  }
  return false;
}
console.log(
  hasCycle({ val: 1, next: { val: 2, next: { val: 3, next: null } } })
);
